#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2022-1-22 10:54
# @Author : huabao.tan
# @File : case_tas6.py
# @Software: PyCharm


import json
import requests
from get_t6_taskuserid.config import *
import time


def dealStr(str, type=None):
    size = len(str)
    a = 5 - size
    if type == None:
        str += "　" * a
    else:
        str += " " * a
    return str


response = requests.post(url=URL, headers=HEADERS, data=json.dumps(DATA)).json()
# response = {}
#
# if not bool(response):
#     print('没有该参数')
if response == None:
    print('Dictionary is empty')
elif not bool(response):
    print('Dictionary is empty')
try:
    res = response['response']['pageData']['results']

    with open(r'C:\Users\huabao.tan.CORP\Desktop\新建文件夹 (2)\TAS6_taskuserid.xlsx', 'w') as f:  #a：追加 w:覆盖
        for a in res:
            now_time = time.localtime(a['createTime']/1000)  #python 时间戳格式只支持10位数，超出就除以至10位数
            dt = time.strftime("%Y-%m-%d %H:%M:%S", now_time)
            print('userName: %s'%dealStr(str(a['userName'])) ,'taskUserId: %s'%dealStr(str(a['taskUserId'])),
                  'passCode: %s'%dealStr(str(a['passCode'])), 'taskId: %s'%dealStr(str(a['taskId'])), '时间：%s'%dealStr(str(dt)), 'userId:%s'%a['userId'])
            f.write(str(a['taskUserId'])+'\n')
    print('该项目下共有：%s人' % len(res))
except Exception as e:
    print(e)



